import 'package:get/get.dart';

class HireRentRentBoxOneLogic extends GetxController {
  int maxCount = 0;
  RxInt selectCount = RxInt(0);
  RxBool subtractionEnable = RxBool(false);
  RxBool addEnable = RxBool(false);
  Function(int count)? selectAction;

  /*
  * 初始化设置最大值
  * */
  initSetMacCount(int? count) {
    maxCount = count ?? 0;
    if (maxCount > 0) {
      addEnable.value = true;
    }
  }

  /*
  * 添加格口
  * */
  addBox() {
    if (addEnable.value == false) {
      return;
    }
    selectCount.value += 1;
    if (selectCount.value == maxCount) {
      addEnable.value = false;
    }
    subtractionEnable.value = true;
    if (selectAction != null) {
      selectAction!(selectCount.value);
    }
  }

  /*
  * 减少格口
  * */
  subtractionBox() {
    if (subtractionEnable.value == false) {
      return;
    }
    selectCount.value -= 1;
    if (selectCount.value == 0) {
      subtractionEnable.value = false;
    }
    addEnable.value = true;
    if (selectAction != null) {
      selectAction!(selectCount.value);
    }
  }
}
